﻿


function NDPriceHelper() {
    this.GetLastestNDPrice = function (func) {
        AysPost2("GetLastestNDPrice",
            func);

    };
    this.AddRoleDb = function (_role, func) {
        AysPost("AddRole",
            { role: _role },
            func);

    };

    this.DeleteUserDb = function (_userNames, func) {
        AysPost("DeleteUserAd",
            { userName: _userNames },
            func);

    };
    this.DeleteRoleDb = function (_role, func) {
        AysPost("DeleteRole",
            { roleName: _role },
            func);

    };
    this.GetUserDb = function (func) {
        AysPost2("GetUserDB",
            {},
            func,
            false);

    };

    this.GetRoleDb = function (func) {
        AysPost("GetRoleDB",
            {},
            func,
            false);

    };

    this.UpdateRoleDb = function (_rolesData, func) {
        AysPost("UpdateRoleDB",
            { rolesData: _rolesData },
            func,
            false);

    };

    this.UpdateUserDb = function (_usersData, func) {
        AysPost("UpdateUserDB",
            { userData: _usersData },
            func,
            false);

    };

}

this.AysPost = function (methodName, postData, func, async) {
    var domain = "/Wcf/serviceAPI.svc/";
    var Async = true;
    if (async == false) {
        Async = false;
    }
    var uriPost = domain + methodName;
    $.ajax({
        type: "POST",
        url: uriPost,
        async: Async,
        data: postData,
        dataType: "json",
        success: function (data) {
            if (func) {
                func(data);
            }
        }
    });
};

this.AysPost2 = function (_methodName, _postData, func, async) {
    var domain = "/page/Handler1.ashx";
    var Async = true;
    if (async == false) {
        Async = false;
    }
    var _data = { metdhodName: _methodName, postData: _postData };
    var uriPost = domain;
    $.ajax({
        type: "POST",
        url: uriPost,
        async: Async,
        data: _data,
        dataType: "json",
        success: function (data) {
            if (func) {
                func(data);
            }
        }
    });
};
